package com.qf.fegin;

import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;

import java.util.Map;
import java.util.Set;

/**
 * @author dell
 * @version V1.0
 * @Date 2022/6/2 14:50:07
 */
@FeignClient(name = "sms-platform-cache")
@RequestMapping("/cache")
public interface CacheFegin {


    /**
     * 保存key-value到redis的String结构中
     * @param key
     * @param value
     * @return
     */
   /* @PostMapping("/save2cache-persist")
    @ApiOperation(value = "保存key-value到redis的String结构中")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "key",value = "数据的key",defaultValue = "test"),
            @ApiImplicitParam(name = "value",value = "数据的value",defaultValue = "test")
    })
    public boolean save(@RequestParam String key,@RequestParam String value);*/

    /**
     * 保存key-value到redis的String结构中,传入的value是Object类型
     * @param key
     * @param value
     * @return
     */
    @PostMapping("/save2cache-object")
    public boolean save(@RequestParam(value = "key") String key,@RequestParam(value = "value") Object value);

    @RequestMapping(value = "/get/{key}", method = RequestMethod.GET)
    public String get(@PathVariable("key") String key);

    @RequestMapping(value = "/get-object/{key}", method = RequestMethod.GET)
    public Object getObject(@PathVariable("key") String key);

    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    public boolean del(@RequestParam("keys") String... keys);

    @RequestMapping(value = "/hmset/{key}", method = RequestMethod.POST)
    public boolean hMSet(@PathVariable("key") String key, @RequestBody Map map);

    @RequestMapping(value = "/hmget/{key}", method = RequestMethod.GET)
    public Map hMGet(@PathVariable("key") String key);

    @RequestMapping(value = "/save2cache", method = RequestMethod.POST)
    public boolean set(@RequestParam("key") String key, @RequestParam("value") String value, @RequestParam("expireSecond") Long expireSecond);

    @RequestMapping(value = "/incr", method = RequestMethod.GET)
    public Long incr(@RequestParam("key") String key, @RequestParam("delta") long delta);

    @RequestMapping(value = "/hget/{key}/{field}",method = RequestMethod.POST)
    public String hget(@PathVariable(value = "key") String key,@PathVariable(value = "field") String field);

    // set结构的add操作
    @RequestMapping(value = "/sadd/{key}",method = RequestMethod.POST)
    public boolean sadd(@PathVariable(value = "key")String key,@RequestParam(value = "set") String... set);

    // set结构的add操作
    @RequestMapping(value = "/sadd-object/{key}",method = RequestMethod.POST)
    public boolean saddObject(@PathVariable(value = "key")String key,@RequestBody Set<Map> set);

    // set结构中的members,获取set中的全部数据
    @RequestMapping(value = "/smembers/{key}",method = RequestMethod.GET)
    public Set<String> smembers(@PathVariable(value = "key") String key);

    // zset结构的根据分数查询数据
    @RequestMapping(value = "/zrangebyscore/{key}",method = RequestMethod.GET)
    public Set<Object> zRangeByScore(@PathVariable(value = "key") String key, @RequestParam("min") Long min, @RequestParam(value = "max") Long max);


    // 对hash结构的某一个field进行incr操作
    @PostMapping("/hincr")
    public Long hincr(@RequestParam(value = "key")String key,@RequestParam(value = "field")String field,@RequestParam(value = "delta")Long delta);

    //通配获取key集合
    @GetMapping(value = "/keys/{key}")
    public Set<String> keys(@PathVariable(value = "key")String key);
}
